package com.kl.drs.util;

import java.io.IOException;
import java.util.Properties;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;

public class ConfigsUtil {
	
	private static String envFlag;
	
	static{
		Properties prop = new Properties();
		try {
			Resource resource = new ClassPathResource("/config/application.properties");
			prop = PropertiesLoaderUtils.loadProperties(resource);
			envFlag = prop.getProperty("spring.profiles.active");
		} catch (IOException e) {
			e.printStackTrace();
			Log4jUtils.logError("ConfigsUtil", "应用配置加载失败！", e);
		}
	}
	public static String getProperty(String key){
		return getProperty(key,"");
	}	
	public static String getProperty(String key,String defual){
		String resultStr = "";
		Properties prop = new Properties();
		try {
			Resource resource = new ClassPathResource("/config/application-"+envFlag+".properties");
			prop = PropertiesLoaderUtils.loadProperties(resource);
			resultStr = prop.getProperty(key, defual);
		} catch (IOException e) {
			e.printStackTrace();
			Log4jUtils.logError("ConfigsUtil", "generalConfig-"+envFlag+".properties配置加载失败！", e);
		}
		return resultStr;
	}
	public static void main(String[] args)
	{
		System.out.println(ConfigsUtil.getProperty("video.path"));
		
	}
}
